package cn.yhr.summerboot.context;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.Collection;
import java.util.HashMap;
import java.util.Map;

/**
 * @Tittle IocApplication
 * @Description
 * @Author yhr
 * @Date 2018/11/26 11:04
 * @Version 1.0
 */
public class IocApplication {
    private Logger logger = LoggerFactory.getLogger(SummerApplication.class);

    private Map ioc = new HashMap(256);

    private IocApplication(){}

    public void put(String key,Object object){
        logger.info(String.valueOf(object.getClass()));
        ioc.put(key, object);
    }

    public Object get(String key){
        return ioc.get(key);
    }

    public void putAll(Map map){
        loggerInfo(map);
        ioc.putAll(map);
    }

    private void loggerInfo(Map map) {
        Collection values = map.values();
        for (Object value : values) {
            logger.info(String.valueOf(value.getClass()));

        }
    }

    public int size(){
        return ioc.size();
    }

    //单例模式
    public Collection<Object> getApplications(){
        return ioc.values();
    }

    public static IocApplication getApplication(){
        return IocApplicationSingle.ioc;
    }

    private static class IocApplicationSingle{
        private static IocApplication ioc=new IocApplication();
    }
}
